package com.yang.demo1.task;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

//@Component
public class DemoTask {
//    @Scheduled(cron = "0/5 * * * * ?") // 每5秒执行一次
    public void execute() {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("hello world: " + df.format(new Date()));
    }

//    @Scheduled(fixedDelay = 5000)
    public void executeFixedDelay() {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("executeFixedDelay开始执行了==========" + df.format(new Date()));
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

//    @Scheduled(fixedRate = 5000)
    public void executeFixedRate() {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.out.println("executeFixedRate开始执行了==========" + df.format(new Date()));
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
